package View.admin;

import agh.rozproszony.model.Room;
import agh.rozproszony.model.User;
import java.util.ArrayList;
import java.util.List;
import javax.swing.table.AbstractTableModel;

public class RoomsTableModel extends AbstractTableModel {

    List<Room> rooms = new ArrayList<Room>();

    public void update(List<Room> rooms) {
        this.rooms = new ArrayList<Room>(rooms);
        fireTableDataChanged();
    }

    @Override
    public int getRowCount() {
        return rooms.size();
    }

    @Override
    public int getColumnCount() {
        return 3;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        Room room = rooms.get(rowIndex);
        switch (columnIndex) {
            case 0:
                return room.getId();
            case 1:
                return room.getName();
            case 2:
                return room.getCapacity();

        }
        throw new RuntimeException("Nieprawidlowy numer kolumny");
    }

    @Override
    public String getColumnName(int column) {
        switch (column) {
            case 0:
                return "ID";
            case 1:
                return "Nazwa";
            case 2:
                return "Pojemność (osób)";

        }
        throw new RuntimeException("Nieprawidłowy numer kolumny");
    }

    public Room getRoomAtRow(int rowId) {
        return rooms.get(rowId);
    }
}
